package com.core.ui.customcell;

import java.util.ArrayList;

import com.core.utils.HTMLTagUtils;
import com.model.KeyValue;

public class TableViewCell {

	private String onCellClick;



	public TableViewCell() {

		this.text = "";
	}



	public String getOnCellClick () {

		return onCellClick;
	}



	public void setOnCellClick ( String onCellClick ) {

		this.onCellClick = onCellClick;
	}



	public void setOnCellClick ( String onCellClickFormat,
	                             Object... objects ) {

		this.onCellClick = String.format(onCellClickFormat, objects);
	}

	private String styleName;



	public String tagName () {

		return "td";
	}



	public String getStyleName () {

		return styleName;
	}



	public void setStyleName ( String styleName ) {

		this.styleName = styleName;
	}



	@Override
	public String toString () {

		String cellText = null;
		if ( onCellClick == null ) {
			cellText = this.text;
		} else {
			cellText = HTMLTagUtils.anchor(onCellClick, "trigger_lnk", this.text);
		}

		String tagName = this.tagName();
		ArrayList <KeyValue> attrs = new ArrayList <KeyValue>();
		attrs.add(new KeyValue("class", styleName, true));
		return HTMLTagUtils.customTag(tagName, attrs, cellText);

	}

	private String text;



	public String getText () {

		return text;
	}



	public void setText ( String text ) {

		this.text = text;
	}

}
